<?php

/**
 * @author	barbarosalcin
 * @desc	page_admin
 * @package	admin
 * @version	$Id: 20110317
 */

$tk->session->data['session_logged_in'] = 1;
$tk->session->data['user_level'] = ADMIN;

if ($tk->session->data['session_logged_in'] == 0)
{
    header("Location: " . $config['docroot'] . "login/" . $config['default_index']);
    exit();
}

if ($tk->session->data['user_level'] < ADMIN)
{
    header("Location: " . $config['docroot'] . $config['default_index']);
    exit();
}

if ($req['request'][1] != $req['request']['end'])
{
    $tk->page->_pv['admin_page'] = $req['request'][1];
}

if ($req['request'][2] != $req['request']['end'])
{
    $tk->page->_pv['admin_request'] = preg_replace('%[^\w_-]+%i', '', $req['request'][2]);
}

if (! $req['ajax'])
{
    include (__PHPROOT__ . 'config/inc.admin_modules.php');
    $tk->assign('admin_modules', $admin_modules);
    $tk->page->_pv['admin_request'] = $tk->page->_pv['admin_request'] ? $tk->page->_pv['admin_request'] : key($admin_modules[$tk->page->_pv['admin_page']]);
}

$tk->page->_pv['base_request'] = preg_replace('%^.+-(.+)$%i', '$1', $tk->page->_pv['admin_request']);

$tk->page->process['info'] = false;

$admin_page = $tk->page->_pv['admin_page'];

$admin_request = $tk->page->_pv['admin_request'];

$base_request = $tk->page->_pv['base_request'];

if (is_file(__PHPROOT__ . 'pages/admin/' . $tk->page->_pv['admin_page'] . '.php'))
{
    include (__PHPROOT__ . 'pages/admin/' . $tk->page->_pv['admin_page'] . '.php');
}
else
{
    $admin_page = $tk->page->_pv['admin_page'] = 'admin_default';
}

$tk->assign('admin_page', $admin_page);
$tk->assign('admin_request', $admin_request);
$tk->assign('base_request', $base_request);

